package jp.sinya.custom_jstl;

import javax.servlet.jsp.JspContext;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.JspFragment;
import javax.servlet.jsp.tagext.JspTag;
import javax.servlet.jsp.tagext.SimpleTag;
import java.io.IOException;

/**
 * 自定义jstl标签，需要先有标签class类，然后配合tld文件使用
 */
public class CustomTag1 implements SimpleTag {
    private PageContext pageContext;
    private JspFragment body;

    /**
     * 其它所有的set××方法，都会在doTag方法之前，被tomcat调用
     *
     * @throws JspException
     * @throws IOException
     */
    @Override
    public void doTag() throws JspException, IOException {
        pageContext.getOut().print("Hello CustomTag");
    }

    @Override
    public void setParent(JspTag jspTag) {

    }

    @Override
    public JspTag getParent() {
        return null;
    }

    @Override
    public void setJspContext(JspContext jspContext) {
        this.pageContext = (PageContext) jspContext;
    }

    @Override
    public void setJspBody(JspFragment jspFragment) {
        this.body = jspFragment;
    }
}
